<?php echo form_tag_for($accountCustomerForm,$accountCustomerForm->getUrl(),array('id'=>'formAccountCustomer',)); ?>
<?php if((! $accountCustomerForm->isValid())&&($accountCustomerForm->isBound())):?>
  <ul class="error_list"><li>Errors on customer form</ul>
    <?php echo $accountCustomerForm->renderGlobalErrors()?>
<?php endif;?>
<div class="infobox1" style="height:150px;">
   <?php include_partial('customer_fields',array('accountCustomerForm'=>$accountCustomerForm,))?>
</div>
<div class="form_buttons">
  <input type="submit" value="Save"/>
    <?php if(! $accountCustomerForm->isNew()):?>
      | <input type="button" value="Delete" id="buttonDeleteAccountCustomer"/>
    <?php endif;?>
    | <input type="button" value="Reset" id="buttonResetAccountCustomer" />
</div>
</form>
<hr/>
<center><input type="button" value="Select" id="buttonSelectContact" style="display:none;"/></center>

<script language="javascript">
  $(document).ready(
  function(){
  accountCustomerSetupForm();
  accountCustomerSetupResetButton('<?php echo $accountCustomerForm->getResetUrl($contact); ?>','<?php echo $accountCustomerForm->isNew()?'Reset form for new customer account?':'Reset customer account for "'.$contact->getListName().'"?'?>');
  <?php if(! $accountCustomerForm->isNew()):?>
    accountCustomerSetupDeleteButton('<?php echo $accountCustomerForm->getDeleteUrl(); ?>','<?php echo 'Delete customer account for "'.$contact->getListName().'"?'?>');
    <?php if($contact->getStatus() == 'ACTIVE'):?>
      switch(contactDialogMode){
        case 10:
          $("#buttonSelectContact").show().click(
            function(){
              showStatusWindow();
              $.get(
                'invoice/create?contact_iden=<?php echo $contact->getIden()?>',{},
                function(content){
                  $("#ajContactPanel").hide();
                  $("#ajContactForm").remove();
                  $("#ajMain").html(content);
                  hideStatusWindow();
                }
              );
            }
          );
          break;
        case 20:
          $("#buttonSelectContact").show().click(
            function(){
              showStatusWindow();
              $.getJSON('accountCustomer/getBalance?contact_iden=<?php echo $contact->getIden()?>',{},
                function(data){
                  if((data.balance>0)||(confirm('Customer has no balance.')))
                    $.get(
                      'payment/createCash?contact_iden=<?php echo $contact->getIden()?>',{},
                      function(content){
                        $("#ajContactPanel").hide();
                        $("#ajContactForm").remove();
                        $("#ajMain").html(content);
                      }
                    );
                  hideStatusWindow();
                }
              );
            }
          );
          break;
        case 21:
          $("#buttonSelectContact").show().click(
            function(){
              showStatusWindow();
              $.getJSON('accountCustomer/getBalance',
                {
                  "contact_iden":"<?php echo $contact->getIden()?>",
                },
                function(data){
                  if((data.balance>0)||(confirm('Customer has no balance.')))
                    $.get(
                      'payment/createCheck?contact_iden=<?php echo $contact->getIden()?>',{},
                      function(content){
                        $("#ajContactPanel").hide();
                        $("#ajContactForm").remove();
                        $("#ajMain").html(content);
                      }
                    );
                  hideStatusWindow();
                }
              );
            }
          );
          break;
        case 22:
          $("#buttonSelectContact").show().click(
            function(){
              showStatusWindow();
              $.get(
                'payment/createOffset?contact_iden=<?php echo $contact->getIden()?>',{},
                function(content){
                  $("#ajContactPanel").hide();
                  $("#ajContactForm").remove();
                  $("#ajMain").html(content);
                  hideStatusWindow();
                }
              );
            }
          );
          break;
        case 30:
          $("#buttonSelectContact").show().click(
            function(){
              showStatusWindow();
              $.get(
                'reportsCustomer/SOA?contact_iden=<?php echo $contact->getIden()?>',{},
                function(content){
                  $("#ajContactPanel").hide();
                  $("#ajContactForm").remove();
                  $("#ajMain").hide();
                  $("#reportsCustomerSearchPanel").show().html(content);
                  hideStatusWindow();
                }
              );
            }
          );
          break;
        case 301:
          $("#buttonSelectContact").show().click(
            function(){
              $('#rkey_SOA_customer_iden').val('<?php echo $contact->getIden()?>');
              $('#reportsCustomerContactListName').html('<?php echo $contact->getListName()?>');
              $("#ajContactPanel").hide();
              $("#ajContactForm").remove();
              $("#ajMain").hide();
              $("#reportsCustomerSearchPanel").show();
            }
          );
          break;
        case 31:
          $("#buttonSelectContact").show().click(
            function(){
              showStatusWindow();
              $.get(
                'reportsCustomer/detailedReceivables?contact_iden=<?php echo $contact->getIden()?>',{},
                function(content){
                  $("#ajContactPanel").hide();
                  $("#ajContactForm").remove();
                  $("#ajMain").hide();
                  $("#reportsCustomerSearchPanel").show().html(content);
                  hideStatusWindow();
                }
              );
            }
          );
          break;
        case 311:
          $("#buttonSelectContact").show().click(
            function(){
              $('#rkey_detailed_receivables_customer_iden').val('<?php echo $contact->getIden()?>');
              $('#reportsCustomerContactListName').html('<?php echo $contact->getListName()?>');
              $("#ajContactPanel").hide();
              $("#ajContactForm").remove();
              $("#ajMain").hide();
              $("#reportsCustomerSearchPanel").show();
            }
          );
          break;
        case 32:
          $("#buttonSelectContact").show().click(
            function(){
              showStatusWindow();
              $.get(
                'reportsCustomer/invoiceSummary?contact_iden=<?php echo $contact->getIden()?>',{},
                function(content){
                  $("#ajContactPanel").hide();
                  $("#ajContactForm").remove();
                  $("#ajMain").hide();
                  $("#reportsCustomerSearchPanel").show().html(content);
                  hideStatusWindow();
                }
              );
            }
          );
          break;
        case 321:
          $("#buttonSelectContact").show().click(
            function(){
              $('#rkey_invoice_summary_customer_iden').val('<?php echo $contact->getIden()?>');
              $('#reportsCustomerContactListName').html('<?php echo $contact->getListName()?>');
              $("#ajContactPanel").hide();
              $("#ajContactForm").remove();
              $("#ajMain").hide();
              $("#reportsCustomerSearchPanel").show();
            }
          );
          break;
      }
    <?php endif;?>
  <?php endif;?>

  });
</script>


